<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Store extends MX_Controller {


	function __construct(){

		$this->load->model('store/store_model');
		
		$this->load->helper(array('form', 'url'));
		
		$this->load->library('form_validation');
		
		$this->load->library('auth/tank_auth');
		
		$this->lang->load('auth/tank_auth');
		
		$this->load->library('session');
	}
	
	function lists($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '5';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/lists/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store',$data);
		}
	}
	
	function grid($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '12';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/grid/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store_grid',$data);
		}
	}
	
	function lists_high($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '5';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product_high($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/lists_high/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product_high($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store_high',$data);
		}
	}
	
	function grid_high($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '12';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product_high($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/grid_high/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product_high($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store_grid_high',$data);
		}
	}
	
	function lists_low($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '5';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product_low($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/lists_low/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product_low($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store_low',$data);	
		}
	}
	
	function grid_low($store){
		
		$data['store'] = $this->store_model->get_store($store);
		
		if($data['store'] == NULL){
			$this->load->view('store/store_not_found');	
		}else{
		
			$offset = $this->uri->segment(4);
			$limit = '12';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['product'] = $this->store_model->get_list_product_low($store, $page, $limit);
			
			$config_pagination['base_url']    = site_url('store/grid_low/'.$store);
			$config_pagination['total_rows']  = count($this->store_model->get_list_product_low($store, 0, 0));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 4;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li><span class="current">';
			$config_pagination['cur_tag_close'] = '</span></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('store/store_grid_low',$data);
		}
	}
	
	function create(){
		if (!Modules::run('auth/is_login'))
			redirect('auth/login2');
			
			$this->form_validation->set_message('is_unique', 'Store name already exists. Please choose another store name.');
			
			$this->form_validation->set_rules('nama_toko','Store Name','required|is_unique[store.nama_toko]');
			
			$data['errors'] = array();
		if ($this->form_validation->run() == FALSE){
			$this->load->view('create_store');
		}else {
			$this->store_model->create($_POST);
			redirect('manager');
		}	
		
	}
	
}

/* End of file common.php */